package com.dsteiner.xelavos.client.domain;

import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.dsteiner.widgets.client.domain.BaseObject;
import com.dsteiner.widgets.client.domain.SearchableProperty;
import com.dsteiner.widgets.client.domain.Sort;
import com.dsteiner.widgets.client.rpc.SearchRequest;

@PersistenceCapable
@EmbeddedOnly
public class SearchRequestXelavos extends BaseObject implements SearchRequest{
	@Persistent
	private String text;
	@Persistent
	private String className;
	@Persistent
	private String sort;
	@Persistent
	private int offset;
	@Persistent
	private int limit = 10;
	@Persistent
	private String annotationClassName = SearchableProperty.class.getName();
	@Persistent
	private int type = TYPE_EQUALS;
	private String toFieldName;
	private String fromFieldName;
	
	public SearchRequestXelavos() {
	}
	
	public SearchRequestXelavos(int type, Sort sort) {
		this.sort = sort.toString();
		this.type = type;
	}
	
	public void setType(int type) {
		this.type = type;
	}
	public int getType() {
		return type;
	}
	public String getAnnotationClassName() {
		return annotationClassName;
	}
	public void setAnnotationClassName(String annotationClassName) {
		this.annotationClassName = annotationClassName;
	}
	public void setOffset(int offset) {
		this.offset = offset;
	}
	public int getOffset() {
		return offset;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getText() {
		return text;
	}
	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public void setSort(Sort sort) {
		this.sort = sort.toString();
	}
	public Sort getSort() {
		return new Sort(sort);
	}

	@Override
	public String toString() {
		return text+"|"+className+"|"+sort+"|"+offset+"|"+limit+"|"+annotationClassName+"|"+type;
	}

	public boolean isEquals() {
		return type == TYPE_EQUALS;
	}
	public boolean isAll() {
		return type == TYPE_ALL;
	}
	public boolean isPrefix() {
		return type == TYPE_PREFIX;
	}

	public String getFromFieldName() {
		return fromFieldName;
	}

	public String getToFieldName() {
		return toFieldName;
	}

	public void setFromFieldName(String fromFieldName) {
		this.fromFieldName = fromFieldName;
	}
	public void setToFieldName(String toFieldName) {
		this.toFieldName = toFieldName;
	}
	public boolean isBetween() {
		return type == TYPE_BETWEEN;
	}
}

